#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n=0,temp=0;
    int count=0;
    vector<int> heap;
    cin>>n;
    cin>>temp;
    heap.push_back(temp);
    for(int i=1;i<n;i++){
        int t=i+1;
        cin>>temp;
        heap.push_back(temp);
        while(t/2!=0){
            if(heap[t-1]<heap[t/2-1]) swap(heap[t-1],heap[t/2-1]);
            t/=2;
        }
    }

    for_each(heap.begin(),heap.end(),[&](int s){
    cout<<s;
    if(count++<n-1)cout<<" ";
    });

    return 0;
}
